package com.zqwm.fly.http;

import com.zqwm.fly.model.Area;
import com.zqwm.fly.service.AreaService;
import com.zqwm.fly.service.WeatherInfo;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 生活指标
 */
@Controller
public class lifeController
{
    @Autowired
    private AreaService areaService;

    //天气

    //日历

    //pm2.5
    @RequestMapping("/getWeather")
    @ResponseBody
    public String getWeather()
    {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("lv",new int[]{2,3});
        List<Area>areaList =areaService.list(map);

        JSONArray jsonArray = new JSONArray();

        for (Area area:areaList)
        {
            JSONObject jsonObject = new JSONObject();
            WeatherInfo weatherInfo = new WeatherInfo(area.getName());
            System.out.println(weatherInfo.getPM25());
            jsonObject.append(area.getName(),weatherInfo.getPM25());
            jsonArray.put(jsonObject);
        }
        System.out.println(jsonArray.toString());

        return jsonArray.toString();
    }
    //房价

    //物价

    //幸福指数

    //平均工资

    //交通


}
